﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SLNGP.Common.Extensions
{
    public static class ListExtensions
    {
        public static void Replace<T>(this ObservableCollection<T> list, T replacingItem, T itemBeingReplaced)
        {
            int index = list.IndexOf(itemBeingReplaced);
            if (index == -1)
                throw new Exception("Cannot perform replace");

            list.RemoveAt(index);
            list.Insert(index, replacingItem);
        }

        public static void Replace<T>(this List<T> list, T replacingItem, T itemBeingReplaced)
        {
            int index = list.IndexOf(itemBeingReplaced);
            if (index == -1)
                throw new Exception("Cannot perform replace");

            list.RemoveAt(index);
            list.Insert(index, replacingItem);
        }

        public static ObservableCollection<T> GetObservableCollection<T>(params T[] Ts)
        {
            ObservableCollection<T> ReturnValue = new ObservableCollection<T>();

            foreach (T t in Ts)
            {
                ReturnValue.Add(t);
            }

            return ReturnValue;
        }
    }
}
